﻿using System;
using System.Collections.Generic;
using System.Text;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Navigation;

namespace ModuleA.ViewModels
{
    public class PersonDetailViewModel:BindableBase,INavigationAware
    {
        private Person _selectedPerson;
        public Person SelectedPerson
        {
            get => _selectedPerson;
            set => SetProperty(ref _selectedPerson, value);
        }
        public PersonDetailViewModel()
        {
        }
        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            var paramters = navigationContext.Parameters;
            if (paramters.TryGetValue("person", out Person person))
            {
                SelectedPerson = person;
            }

        }

        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            var person = navigationContext.Parameters["person"] as Person;
            if (person != null)
                return SelectedPerson != null && SelectedPerson.LastName == person.LastName;
            else
                return true;
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
        }
    }
}
